﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UtilZ.Dotnet.Ex.Base;

namespace ConsoleApp.Test
{
    internal class TestArrayEx
    {
        public static void Test()
        {

            //int max = GetMax();
            //Validate(max);
            ValidateMaxLength();
        }

        private static void ValidateMaxLength()
        {
            try
            {
                int count1 = ArrayEx.MaxLength - 1;
                byte[] buffer2 = new byte[count1];

                int count2 = ArrayEx.MaxLength;
                byte[] buffer3 = new byte[count2];

                int count3 = ArrayEx.MaxLength + 1;
                byte[] buffer4 = new byte[count3];
            }
            catch (Exception ex)
            {

            }
        }



        private static void Validate(int max)
        {
            try
            {

                byte[] buffer1 = new byte[100];

                int count1 = max - 1;
                byte[] buffer2 = new byte[count1];

                int count2 = max;
                byte[] buffer3 = new byte[count2];

                int count3 = max + 1;
                byte[] buffer4 = new byte[count3];
            }
            catch (Exception ex)
            {

            }
        }

        private static int GetMax()
        {
            //int max = 2130702268;
            int max = 0;//1459633268

            //672992049
            for (int i = 690116184; ; i+=10000000)
            {
                try
                {
                    Console.WriteLine(i);
                    byte[] buffer = new byte[i];

                    int count1 = i - 1;
                    byte[] buffer2 = new byte[count1];

                    int count2 = i;
                    byte[] buffer3 = new byte[count2];

                    int count3 = i + 1;
                    try
                    {
                        byte[] buffer4 = new byte[count3];
                    }
                    catch (Exception exi)
                    {
                        //i	672992049	int
                        //i 653653101   int
                        //i	654653101	int

                    }

                    
                }
                catch (Exception ex)
                {
                    //		i	670992049	int
                    max = i;
                    break;
                }
            }

            //		i	2130702268	int



            //654653101
            return max;
        }

    }
}
